package com.orange.wwwapi.controller.writeoff;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.req.writeoff.WriteOffPageReq;
import com.orange.core.pojo.rsp.writeoff.WriteOffCountRsp;
import com.orange.core.pojo.rsp.writeoff.WriteOffResultRsp;
import com.orange.core.pojo.rsp.writeoff.WriteOffRsp;
import com.orange.core.service.writeoff.WriteOffService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 核销
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/writeOff")
public class WriteOffController {

    private final WriteOffService writeOffService;

    /**
     * 核销统计
     */
    @GetMapping("/count")
    public R<WriteOffCountRsp> writeOffCount() {
        return R.ok(writeOffService.writeOffCount());
    }

    /**
     * 核销
     *
     * @param writeOffNo 核销码
     */
    @PostMapping("/{writeOffNo}")
    public R<WriteOffResultRsp> writeOff(@PathVariable String writeOffNo) {
        return R.ok(writeOffService.writeOff(writeOffNo));
    }

    /**
     * 核销列表
     */
    @PostMapping("/page")
    public R<Page<WriteOffRsp>> writeOffPage(@RequestBody PageReqDto<WriteOffPageReq> req) {
        return R.ok(writeOffService.writeOffPage(req));
    }
}
